/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The impact of divorce laws on the equilibrium in the marriage market.
% Ana Reynoso
% April 2024
%
% This file inputs the raw PSID data and cleans it for this project.
%  
% Data: PSID 1968-1992
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/

*%------------------------ Replication Path -------------------------------%

clear all
clear
set mem 1000M
set maxvar 15000

*%--- Indicate location of Replication folder:

*global replication_location "C:\update_with_your_path"

*global rawdata "D:\update_with_the_path_where_you_stored_the_raw_data"

cd "$replication_location\Data\Inputs"


***********************************************************
***** 1. Selected variables from the individuals file *****
***********************************************************

use "$rawdata\IND2011ER.dta", clear

* Identification of samples
gen latsample=(ER30001>=7001 & ER30001<=9308)
gen seosample=(ER30001>=5001 & ER30001<=6872)
gen immsample=(ER30001>=3001 & ER30001<=3511)

*id is the family interview number for that specific year
ren ER30001 id67
ren ER30020 id68
ren ER30043 id69
ren ER30067 id70 
ren ER30091 id71 
ren ER30117 id72 
ren ER30138 id73
ren ER30160 id74
ren ER30188 id75
ren ER30217 id76
ren ER30246 id77
ren ER30283 id78
ren ER30313 id79
ren ER30343 id80
ren ER30373 id81
ren ER30399 id82
ren ER30429 id83
ren ER30463 id84
ren ER30498 id85
ren ER30535 id86
ren ER30570 id87
ren ER30606 id88
ren ER30642 id89
ren ER30689 id90
ren ER30733 id91
ren ER30806 id92
ren ER33101 id93
ren ER33201 id94
ren ER33301 id95
ren ER33401 id96
ren ER33501 id98
ren ER33601 id100
ren ER33701 id102
ren ER33801 id104
ren ER33901 id106
ren ER34001 id108
ren ER34101 id110

*sequence number=status: whether living/joined after/dead/institution/moved away/etc
*NO PSID-1968 sequence number
rename ER30021 seqnum68
rename ER30044 seqnum69
rename ER30068 seqnum70
rename ER30092 seqnum71
rename ER30118 seqnum72
rename ER30139 seqnum73
rename ER30161 seqnum74
rename ER30189 seqnum75
rename ER30218 seqnum76
rename ER30247 seqnum77
rename ER30284 seqnum78
rename ER30314 seqnum79
rename ER30344 seqnum80
rename ER30374 seqnum81
rename ER30400 seqnum82
rename ER30430 seqnum83
rename ER30464 seqnum84
rename ER30499 seqnum85
rename ER30536 seqnum86
rename ER30571 seqnum87
rename ER30607 seqnum88
rename ER30643 seqnum89
rename ER30690 seqnum90
rename ER30734 seqnum91
rename ER30807 seqnum92
rename ER33102 seqnum93
rename ER33202 seqnum94
rename ER33302 seqnum95
rename ER33402 seqnum96
rename ER33502 seqnum98
rename ER33602 seqnum100
rename ER33702 seqnum102
rename ER33802 seqnum104
rename ER33902 seqnum106
rename ER34002 seqnum108
rename ER34102 seqnum110

* gender

rename ER32000 gender

*relationship to head of current household
rename ER30003 relhead67
rename ER30022 relhead68
rename ER30045 relhead69
rename ER30069 relhead70
rename ER30093 relhead71
rename ER30119 relhead72
rename ER30140 relhead73
rename ER30162 relhead74
rename ER30190 relhead75
rename ER30219 relhead76
rename ER30248 relhead77
rename ER30285 relhead78
rename ER30315 relhead79
rename ER30345 relhead80
rename ER30375 relhead81
rename ER30401 relhead82
rename ER30431 relhead83
rename ER30465 relhead84
rename ER30500 relhead85
rename ER30537 relhead86
rename ER30572 relhead87
rename ER30608 relhead88
rename ER30644 relhead89
rename ER30691 relhead90
rename ER30735 relhead91
rename ER30808 relhead92
rename ER33103 relhead93
rename ER33203 relhead94
rename ER33303 relhead95
rename ER33403 relhead96
rename ER33503 relhead98
rename ER33603 relhead100
rename ER33703 relhead102
rename ER33803 relhead104
rename ER33903 relhead106
rename ER34003 relhead108
rename ER34103 relhead110

* Education
rename	ER30010	educ67 
rename	ER30052	educ69 
rename	ER30076	educ70 
rename	ER30100	educ71 
rename	ER30126	educ72 
rename	ER30147	educ73 
rename	ER30169	educ74 
rename	ER30197	educ75
rename	ER30226	educ76
rename	ER30255	educ77
rename	ER30296	educ78
rename	ER30326	educ79
rename	ER30356	educ80
rename	ER30384	educ81
rename	ER30413	educ82
rename	ER30443	educ83
rename	ER30478	educ84
rename	ER30513	educ85
rename	ER30549	educ86
rename	ER30584	educ87
rename	ER30620	educ88
rename	ER30657	educ89
rename	ER30703	educ90
rename	ER30748	educ91
rename	ER30820	educ92
rename	ER33115	educ93
rename	ER33215	educ94
rename	ER33315	educ95
rename	ER33415	educ96
rename	ER33516	educ98
rename	ER33616	educ100
rename	ER33716	educ102
rename	ER33817	educ104
rename	ER33917	educ106
rename	ER34020	educ108
rename  ER34119 educ110

* Education cross year
rename ER30110 educ_cy71			
rename ER30181 educ_cy74

* Still at school for 1968 only
rename ER30009 in_school68

*AGE
rename ER30004 age67
rename ER30023 age68
rename ER30046 age69
rename ER30070 age70
rename ER30094 age71
rename ER30120 age72
rename ER30141 age73
rename ER30163 age74
rename ER30191 age75
rename ER30220 age76
rename ER30249 age77
rename ER30286 age78
rename ER30316 age79
rename ER30346 age80
rename ER30376 age81
rename ER30402 age82
rename ER30432 age83
rename ER30466 age84
rename ER30501 age85
rename ER30538 age86
rename ER30573 age87
rename ER30609 age88
rename ER30645 age89
rename ER30692 age90
rename ER30736 age91
rename ER30809 age92
rename ER33104 age93
rename ER33204 age94
rename ER33304 age95
rename ER33404 age96
rename ER33504 age98
rename ER33604 age100
rename ER33704 age102
rename ER33804 age104
rename ER33904 age106
rename ER34004 age108
rename ER34104 age110

* Marriage pair indicator
rename	ER30005	marpair67
rename	ER30024	marpair68
rename	ER30047	marpair69
rename	ER30071	marpair70
rename	ER30095	marpair71
rename	ER30121	marpair72
rename	ER30142	marpair73
rename	ER30164	marpair74
rename	ER30192	marpair75
rename	ER30221	marpair76
rename	ER30250	marpair77
rename	ER30287	marpair78
rename	ER30317	marpair79
rename	ER30347	marpair80
rename	ER30377	marpair81
rename	ER30405	marpair82
rename	ER30435	marpair83
rename	ER30469	marpair84
rename	ER30504	marpair85
rename	ER30541	marpair86
rename	ER30576	marpair87
rename	ER30612	marpair88
rename	ER30648	marpair89
rename	ER30695	marpair90
rename	ER30739	marpair91
rename	ER30812	marpair92
rename	ER33107	marpair93
rename	ER33207	marpair94
rename	ER33307	marpair95
rename	ER33407	marpair96
rename	ER33507	marpair98
rename	ER33607	marpair100
rename	ER33707	marpair102
rename	ER33807	marpair104
rename	ER33907	marpair106
rename	ER34007	marpair108
rename	ER34107	marpair110

* Moved in or out: indicator
rename	ER30006	moved_in_out67
rename	ER30025	moved_in_out68
rename	ER30048	moved_in_out69
rename	ER30072	moved_in_out70
rename	ER30096	moved_in_out71
rename	ER30122	moved_in_out72
rename	ER30143	moved_in_out73
rename	ER30165	moved_in_out74
rename	ER30193	moved_in_out75
rename	ER30222	moved_in_out76
rename	ER30251	moved_in_out77
rename	ER30288	moved_in_out78
rename	ER30318	moved_in_out79
rename	ER30348	moved_in_out80
rename	ER30378	moved_in_out81
rename	ER30406	moved_in_out82
rename	ER30436	moved_in_out83
rename	ER30470	moved_in_out84
rename	ER30505	moved_in_out85
rename	ER30542	moved_in_out86
rename	ER30577	moved_in_out87
rename	ER30613	moved_in_out88
rename	ER30649	moved_in_out89
rename	ER30696	moved_in_out90
rename	ER30740	moved_in_out91
rename	ER30813	moved_in_out92
rename	ER33108	moved_in_out93
rename	ER33208	moved_in_out94
rename	ER33308	moved_in_out95
rename	ER33408	moved_in_out96
rename	ER33508	moved_in_out98
rename	ER33608	moved_in_out100
rename	ER33708	moved_in_out102
rename	ER33808	moved_in_out104
rename	ER33908	moved_in_out106
rename	ER34008	moved_in_out108
rename	ER34108	moved_in_out110

* Moved in or out: month
rename	ER30007	moved_month67
rename	ER30026	moved_month68
rename	ER30049	moved_month69
rename	ER30073	moved_month70
rename	ER30097	moved_month71
rename	ER30123	moved_month72
rename	ER30144	moved_month73
rename	ER30166	moved_month74
rename	ER30194	moved_month75
rename	ER30223	moved_month76
rename	ER30252	moved_month77
rename	ER30289	moved_month78
rename	ER30319	moved_month79
rename	ER30349	moved_month80
rename	ER30379	moved_month81
rename	ER30407	moved_month82
rename	ER30437	moved_month83
rename	ER30471	moved_month84
rename	ER30506	moved_month85
rename	ER30543	moved_month86
rename	ER30578	moved_month87
rename	ER30614	moved_month88
rename	ER30650	moved_month89
rename	ER30697	moved_month90
rename	ER30741	moved_month91
rename	ER30814	moved_month92
rename	ER33109	moved_month93
rename	ER33209	moved_month94
rename	ER33309	moved_month95
rename	ER33409	moved_month96
rename	ER33509	moved_month98
rename	ER33609	moved_month100
rename	ER33709	moved_month102
rename	ER33809	moved_month104
rename	ER33909	moved_month106
rename	ER34009	moved_month108
rename	ER34109	moved_month110

* Moved in or out: year
rename	ER30008	moved_year67
rename	ER30027	moved_year68
rename	ER30050	moved_year69
rename	ER30074	moved_year70
rename	ER30098	moved_year71
rename	ER30124	moved_year72
rename	ER30145	moved_year73
rename	ER30167	moved_year74
rename	ER30195	moved_year75
rename	ER30224	moved_year76
rename	ER30253	moved_year77
rename	ER30290	moved_year78
rename	ER30320	moved_year79
rename	ER30350	moved_year80
rename	ER30380	moved_year81
rename	ER30408	moved_year82
rename	ER30438	moved_year83
rename	ER30472	moved_year84
rename	ER30507	moved_year85
rename	ER30544	moved_year86
rename	ER30579	moved_year87
rename	ER30615	moved_year88
rename	ER30651	moved_year89
rename	ER30698	moved_year90
rename	ER30742	moved_year91
rename	ER30815	moved_year92
rename	ER33110	moved_year93
rename	ER33210	moved_year94
rename	ER33310	moved_year95
rename	ER33410	moved_year96
rename	ER33510	moved_year98
rename	ER33610	moved_year100
rename	ER33710	moved_year102
rename	ER33810	moved_year104
rename	ER33910	moved_year106
rename	ER34010	moved_year108
rename	ER34110	moved_year110

* Individual sample weight 
rename	ER30019	sample_weight67	
rename	ER30042	sample_weight68	
rename	ER30066	sample_weight69	
rename	ER30090	sample_weight70	
rename	ER30116	sample_weight71	
rename	ER30137	sample_weight72	
rename	ER30159	sample_weight73	
rename	ER30187	sample_weight74	
rename	ER30216	sample_weight75	
rename	ER30245	sample_weight76	
rename	ER30282	sample_weight77	
rename	ER30312	sample_weight78	
rename	ER30342	sample_weight79	
rename	ER30372	sample_weight80	
rename	ER30398	sample_weight81	
rename	ER30428	sample_weight82	
rename	ER30462	sample_weight83	
rename	ER30497	sample_weight84	
rename	ER30534	sample_weight85	
rename	ER30569	sample_weight86	
rename	ER30605	sample_weight87	
rename	ER30641	sample_weight88	
rename	ER30686	sample_weight89	
rename	ER30730	sample_weight90	
rename	ER30803	sample_weight91	

* Id of main family of split off individual 
rename	ER30039	splitoff_famid68
rename	ER30063	splitoff_famid69
rename	ER30087	splitoff_famid70
rename	ER30113	splitoff_famid71
rename	ER30134	splitoff_famid72
rename	ER30156	splitoff_famid73
rename	ER30184	splitoff_famid74
rename	ER30213	splitoff_famid75
rename	ER30242	splitoff_famid76
rename	ER30279	splitoff_famid77
rename	ER30309	splitoff_famid78
rename	ER30339	splitoff_famid79
rename	ER30369	splitoff_famid80
rename	ER30395	splitoff_famid81
rename	ER30424	splitoff_famid82
rename	ER30458	splitoff_famid83
rename	ER30493	splitoff_famid84
rename	ER30530	splitoff_famid85
rename	ER30565	splitoff_famid86
rename	ER30601	splitoff_famid87
rename	ER30637	splitoff_famid88
rename	ER30679	splitoff_famid89
rename	ER30722	splitoff_famid90
rename	ER30797	splitoff_famid91
rename	ER30858	splitoff_famid92
rename	ER33124	splitoff_famid93
rename	ER33280	splitoff_famid94
rename	ER33321	splitoff_famid95
rename	ER33433	splitoff_famid96
rename	ER33541	splitoff_famid98
rename	ER33632	splitoff_famid100
rename	ER33735	splitoff_famid102
rename	ER33841	splitoff_famid104
rename	ER33941	splitoff_famid106
rename	ER34035	splitoff_famid108
rename	ER34147	splitoff_famid110

* Split off year
rename	ER30038	splitoff_year68
rename	ER30062	splitoff_year69
rename	ER30086	splitoff_year70
rename	ER30112	splitoff_year71
rename	ER30133	splitoff_year72
rename	ER30155	splitoff_year73
rename	ER30183	splitoff_year74
rename	ER30212	splitoff_year75
rename	ER30241	splitoff_year76
rename	ER30278	splitoff_year77
rename	ER30308	splitoff_year78
rename	ER30338	splitoff_year79
rename	ER30368	splitoff_year80
rename	ER30394	splitoff_year81
rename	ER30423	splitoff_year82
rename	ER30457	splitoff_year83
rename	ER30492	splitoff_year84
rename	ER30529	splitoff_year85
rename	ER30564	splitoff_year86
rename	ER30600	splitoff_year87
rename	ER30636	splitoff_year88
rename	ER30678	splitoff_year89
rename	ER30721	splitoff_year90
rename	ER30796	splitoff_year91
rename	ER30857	splitoff_year92
rename	ER33123	splitoff_year93
rename	ER33279	splitoff_year94
rename	ER33320	splitoff_year95
rename	ER33432	splitoff_year96
rename	ER33540	splitoff_year98
rename	ER33631	splitoff_year100
rename	ER33734	splitoff_year102
rename	ER33840	splitoff_year104
rename	ER33940	splitoff_year106
rename	ER34034	splitoff_year108
rename	ER34146	splitoff_year110

* Split off month
rename	ER30037	splitoff_month68
rename	ER30061	splitoff_month69
rename	ER30085	splitoff_month70
rename	ER30111	splitoff_month71
rename	ER30132	splitoff_month72
rename	ER30154	splitoff_month73
rename	ER30182	splitoff_month74
rename	ER30211	splitoff_month75
rename	ER30240	splitoff_month76
rename	ER30277	splitoff_month77
rename	ER30307	splitoff_month78
rename	ER30337	splitoff_month79
rename	ER30367	splitoff_month80
rename	ER30393	splitoff_month81
rename	ER30422	splitoff_month82
rename	ER30456	splitoff_month83
rename	ER30491	splitoff_month84
rename	ER30528	splitoff_month85
rename	ER30563	splitoff_month86
rename	ER30599	splitoff_month87
rename	ER30635	splitoff_month88
rename	ER30677	splitoff_month89
rename	ER30720	splitoff_month90
rename	ER30795	splitoff_month91
rename	ER30856	splitoff_month92
rename	ER33122	splitoff_month93
rename	ER33278	splitoff_month94
rename	ER33319	splitoff_month95
rename	ER33431	splitoff_month96
rename	ER33539	splitoff_month98
rename	ER33630	splitoff_month100
rename	ER33733	splitoff_month102
rename	ER33839	splitoff_month104
rename	ER33939	splitoff_month106
rename	ER34033	splitoff_month108
rename	ER34145	splitoff_month110

* Housework: weekly hours
rename	ER30029	housework_weklyhrs68
rename	ER30053	housework_weklyhrs69
rename	ER30077	housework_weklyhrs70
rename	ER30102	housework_weklyhrs71
rename	ER30127	housework_weklyhrs72
rename	ER30148	housework_weklyhrs73
rename	ER30198	housework_weklyhrs75
rename	ER30227	housework_weklyhrs76
rename	ER30256	housework_weklyhrs77
rename	ER30291	housework_weklyhrs78
rename	ER30321	housework_weklyhrs79
rename	ER30351	housework_weklyhrs80
rename	ER30409	housework_weklyhrs82
rename	ER30439	housework_weklyhrs83
rename	ER30473	housework_weklyhrs84
rename	ER30508	housework_weklyhrs85

* Annual hours of work (only available from PSID-68 to PSID-93)
rename	ER30013	hrs_wk_annual67	
rename	ER30034	hrs_wk_annual68	
rename	ER30058	hrs_wk_annual69	
rename	ER30082	hrs_wk_annual70	
rename	ER30107	hrs_wk_annual71	
rename	ER30131	hrs_wk_annual72	
rename	ER30153	hrs_wk_annual73	
rename	ER30177	hrs_wk_annual74	
rename	ER30204	hrs_wk_annual75	
rename	ER30233	hrs_wk_annual76	
rename	ER30270	hrs_wk_annual77	
rename	ER30300	hrs_wk_annual78	
rename	ER30330	hrs_wk_annual79	
rename	ER30360	hrs_wk_annual80	
rename	ER30388	hrs_wk_annual81	
rename	ER30417	hrs_wk_annual82	
rename	ER30447	hrs_wk_annual83	
rename	ER30482	hrs_wk_annual84	
rename	ER30517	hrs_wk_annual85	
rename	ER30553	hrs_wk_annual86	
rename	ER30588	hrs_wk_annual87	
rename	ER30624	hrs_wk_annual88	
rename	ER30661	hrs_wk_annual89	
rename	ER30709	hrs_wk_annual90	
rename	ER30754	hrs_wk_annual91	
rename	ER30823	hrs_wk_annual92	

* Marriage history variables:
rename ER32033 marital_latest_info
rename ER32034 nbr_marriages
rename ER32035 month_firstmarriage
rename ER32036 year_firstmarriage
rename ER32037 status_first
rename ER32038 end_firstmarriage_month
rename ER32039 end_firstmarriage_year
rename ER32040 sep_firstmarriage_month
rename ER32041 sep_firstmarriage_year
rename ER32042 month_recentmarriage
rename ER32043 year_recentmarriage
rename ER32044 status_recent
rename ER32045 end_recent_month
rename ER32046 end_recent_year
rename ER32047 sep_recent_month
rename ER32048 sep_recent_year

* Person unique identification throughout all PSID waves: combination of person id and number of family unit in 1968 (1968 FU)
*- Person id
rename ER30002 IDperson
*- 1968 FU
gen orignialFU=id67
gen person=orignialFU*1000+IDperson
* We keep only the core sample
drop if latsample==1
drop if immsample==1
* Keep relevant variables 
keep IDperson person orignialFU seosample immsample latsample id* relhead* gender seqnum* educ* in_school68 age* moved_year* moved_month* moved_in_out* marpair* hrs_wk_annual* housework_weklyhrs* splitoff_month* splitoff_year* splitoff_famid* sample_weight* marital_latest_info nbr_marriages month_firstmarriage year_firstmarriage status_first end_firstmarriage_month end_firstmarriage_year sep_firstmarriage_month sep_firstmarriage_year month_recentmarriage year_recentmarriage status_recent end_recent_month end_recent_year sep_recent_month sep_recent_year

* Fill in the education values for years 1968 to 1974 based on ER30110 and ER30181 variables
br person age68 educ* in_school68 if age68>=20
gen educ68=.
replace educ68=educ_cy71 if educ67==educ_cy71
replace educ69=educ_cy71 if educ67==educ_cy71
replace educ70=educ_cy71 if educ67==educ_cy71
replace educ71=educ_cy71 if educ67==educ_cy71
replace educ72=educ74 if educ74==educ71&educ74==educ_cy74
replace educ73=educ74 if educ74==educ71&educ74==educ_cy74

* Reshape
order IDperson id67
reshape long id relhead seqnum educ educ_cy age moved_year moved_month moved_in_out marpair hrs_wk_annual housework_weklyhrs splitoff_month splitoff_year splitoff_famid sample_weight, i(person) j(year)

* Year in right format
replace year=1900+year

* Order and Label variables
order  year orignialFU  id person IDperson relhead  marpair gender age in_school68 educ educ_cy hrs_wk_annual housework_weklyhrs  moved_in_out moved_month moved_year splitoff_famid splitoff_month splitoff_year latsample seosample immsample sample_weight
sort year orignialFU id IDperson
label var orignialFU "ID of parent household in 1968"
label var id "ID of current household in subsequent PSID waves"
label var marpair "ID number of a couple"
label var hrs_wk_annual "Total hours worked in the year"
label var housework_weklyhrs "Total hours worked on average per week"
label var moved_in_out "Moved in/Moved Out Indicator"
notes moved_in_out: 1=moved in or born, or split off, between previous interview and this one, 2=Appeared; moved in by the time the 1970 interview was taken but not included in FU on previous interviews(usually a listing error), 5=Moved out of FU or institution between 1970 and 1971interviews and was not included in a 1971 panel FU, 6=Moved out of FU and into an institution between the 1970 and 1971 interviews, 7=Living in 1970 but died by the time of the 1971 interview, 8=Disappeared; moved out prior to the 1970 interview but included in FU for 1970 (usually a listing error)
label var splitoff_famid "Current family ID of family from which splitoff moved"
notes splitoff_famid: This the current id of the parent family in the corresponding PSID year from which the person who split off came.

* Save
save "individuals.dta", replace

***********************************************************
***** 2. Construct a head/wife file *****
***********************************************************
u "individuals.dta", clear

* Kep only heads and spouses
keep if relhead==1 | relhead==10 | relhead==2 | relhead==20 | relhead==22

* Indicator for head (1) or spouse (0)
gen head=(relhead==1 | relhead==10)

* Check the number of heads per household. 
by id year head, sort: gen N=_N

* Sample member indicator
gen sample_member=.
replace sample_member=1 if IDperson<170
replace sample_member=0 if IDperson>=170

* Order and sort
order orignialFU year id IDperson sample_member N
sort orignialFU year id IDperson sample_member 

* Save
save "onlyheadsandspouse.dta", replace

* Create a spouse file
keep if head==0

* Create a variable indicating reason for change in spouse
gen comp_change=.
// households with two spouses
replace comp_change=1 if seqnum>=51 & seqnum<=59 & N==2 
replace comp_change=2 if seqnum>=71 & seqnum<=80 & N==2 
replace comp_change=3 if seqnum>=81 & seqnum<=89 & N==2 
// household with one spouse but with sequence number greater than 2	
replace comp_change=4 if seqnum>=51 & seqnum<=59 & N==1 
replace comp_change=5 if seqnum>=71 & seqnum<=80 & N==1 
replace comp_change=6 if seqnum>=81 & seqnum<=89 & N==1 	
sort N orignialFU id
egen hh= group(year id) if N>1
sum hh
forvalues i=1(1)151{
qui sum comp_change if hh==`i'
qui replace comp_change=r(max) if hh==`i'
}
label define lbl_comp_change 1 "sp institution & another" 2 "sp est own hh & another" 3 "sp died & another" 4 "sp institution & no" 5 "sp est own hh & no" 6 "sp died & no"
label values comp_change lbl_comp_change
order orignialFU year id IDperson N comp_change person
sort orignialFU year id IDperson 
drop if seqnum>20 & N==2 
foreach var of varlist  IDperson - head{
rename `var' s_`var'
}
sort year id
save "onlyspouse.dta", replace

* Merge spouse data to heads data
u "onlyheadsandspouse.dta", clear
drop if head==0
* Create a variable indicating reason for change in spouse
gen comp_change_hd=.
replace comp_change_hd=1 if seqnum>=51 & seqnum<=59 & N==2 
replace comp_change_hd=2 if seqnum>=71 & seqnum<=80 & N==2 
replace comp_change_hd=3 if seqnum>=81 & seqnum<=89 & N==2 
replace comp_change_hd=4 if N==3 
egen hh= group(year id) if N>1
sum hh
forvalues i=1(1)4687{
qui sum comp_change_hd if hh==`i'
qui replace comp_change_hd=r(max) if hh==`i'
}
label define lbl_comp_change_hd 1 "hd institution & another" 2 "hd est own hh & another" 3 "hd died & another" 4 "three heads"
label values comp_change_hd lbl_comp_change_hd
order orignialFU year id IDperson N comp_change person
* Keep only heads that are not mover outs
keep if (seqnum>=1 & seqnum<=20) | seqnum==. 
sort year id
merge year id using "onlyspouse.dta"

foreach var of varlist s_relhead - s_sep_recent_year{
replace `var'=. if s_seqnum>20 & s_seqnum!=.
}

* Order
sort orignialFU year id 

* Save
save "couples.dta", replace

* Keep only PSID sample members
u couples.dta, clear
keep if sample_member==1 | s_sample_member==1 // I keep households where either the head or the wife or both are sample members

save "couples_psid.dta", replace

***********************************************************
***** 3. Edit Household level variables *****
***********************************************************

use "$rawdata/fam1968", clear
#delimit;
keep V93 V95 V47 V3 V117 V118 V119 V398 V196 V198 V181 V81 V74 V75 V76 V79 
     V337 V239 V439 V313 V115 V37 V83 V53 V45 V315 V10 V5 V14 V143 V251 V246 V196 V318;
#delimit cr  
ren	V318	father_educ
ren	V3	id67
gen id=id67
ren V251  wages
ren V14    util          
ren V143  ncars
ren V5    house
ren V10    rent
gen       disab=.
gen      outkid=.
ren V315    vet
ren V45   fstmp
ren V53   hourw
ren V93   state
ren V95    smsa
ren V47   hours
*ren V117    age
*ren V118   agew
ren V119    sex
ren V398   kids
ren V196  empst
ren V198   self
ren V181   race
ren V81       y
ren V74      ly
ren V75     wly
ren V76    tyhw
ren V79   tyoth
gen      troth=0
gen        trhw=y-tyhw-tyoth
ren V337   avhy
ren V239  marit
ren V439 weight
ren V313   educ
ren V246   weduc
ren V115  fsize
gen       split=0
gen        fchg=0
gen       newhd=0
ren V37    food
gen        fout=.
ren V83    ftax
gen 	    asset=.
gen        trhf=.
gen year=1967
tempfile fam67
save `fam67',replace

use "$rawdata/fam1969", clear

#delimit;
keep V537 V539 V909 V542 V465 V493 V442 V1008 V1010 V1011 V550 V639 V641 V791 V801 
     V529 V514 V516 V518 V521 V527  V639
     V871 V607 V1014 V794 V500 V506 V532 V525 V475 V510 V796 V732 V743 V455 V449 V460 V581 V699 V534 V793;
#delimit cr
ren	V793	father_educ
ren	V534	id67
ren V699   wages
ren V460    util 
ren V581   ncars
ren V449   house
ren V455    rent
ren V743   disab
ren V732  outkid
ren V796     vet
ren V510   fstmp
ren V475   hourw
ren V537   state
ren V539    smsa
ren V909   split
ren V542    fchg
ren V465   hours
ren V493   fsize
ren V442      id
*ren V1008    age
*ren V1011   agew
ren V1010    sex
ren V550    kids
ren V639   empst
ren V641    self
ren V791   newhd
ren V801    race
ren V529       y
ren V514      ly
ren V516     wly
ren V518    tyhw
ren V521   tyoth
ren V527   troth
ren V525    trhw
ren V871    avhy
ren V607   marit
ren V1014 weight
ren V794    educ
gen weduc=.
ren V500    food
ren V506    fout
ren V532    ftax
gen        asset=.
gen         trhf=.
gen year=1968
tempfile fam68
save `fam68',replace

use "$rawdata/fam1970", clear
#delimit;
keep V1103 V1506 V1106 V1109 V1138 V1167 V1102 V1239 V1240 V1241 V1242 V1278 V1280 V1461 V1490 
     V1514 V1196 V1198 V1205 V1222 V1225 V1220 V1278
     V1567 V1365 V1609 V1485 V1175 V1185 V1122 V1208 V1224 V1148 V1183 V1487 V1399 V1409 V1128 V1122 V1133 V1254 V1191 V1230 V1484;
#delimit cr   
ren	V1484	father_educ
ren	V1230	id67
ren V1191   wages
ren V1133    util 
ren V1254   ncars
ren V1122   house
ren V1128    rent
ren V1409   disab
ren V1399  outkid
ren V1487     vet
ren V1183   fstmp
ren V1148   hourw
ren V1103   state
ren V1506    smsa
ren V1106   split
ren V1109    fchg
ren V1138   hours
ren V1167   fsize
ren V1102      id
*ren V1239     age
*ren V1241    agew
ren V1240     sex
ren V1242    kids
ren V1278   empst
ren V1280    self
ren V1461   newhd
ren V1490    race
ren V1514       y
ren V1196      ly
ren V1198     wly
ren V1205    tyhw
ren V1222   tyoth
ren V1225   troth
ren V1220    trhw
ren V1567    avhy
ren V1365   marit
ren V1609  weight
ren V1485    educ
gen weduc=.
ren V1175    food
ren V1185    fout
gen          ftax=V1208+V1224 if V1208!=. & V1224!=.
replace      ftax=V1208       if V1208!=. & V1224==.
replace      ftax=V1224       if V1208==. & V1224!=.
drop V1208 V1224
gen 	      asset=.
gen          trhf=.
gen year=1969
tempfile fam69
save `fam69',replace


use "$rawdata/fam1971", clear
#delimit;
keep V1803 V1816 V1806 V1809 V1839 V1868 V1802 V1942 V1943 V1944 V1945 V1983 V1986 V2165 V2202 
     V2226 V1897 V1899 V1906 V1924 V1927 V1922 V1983
     V2279 V2072 V2321 V2197 V1876 V1886 V1910 V1926 V1849 V1884 V2199 V2111 V2121 V1829 V1823 V1834 V1957 V1892 V1932 V2196;
#delimit cr  
ren	V2196	father_educ
ren	V1932	id67
ren V1892   wages
ren V1834    util 
ren V1957   ncars
ren V1823   house
ren V1829    rent
ren V2121   disab
ren V2111  outkid
ren V2199     vet
ren V1884   fstmp
ren V1849   hourw
ren V1803   state
ren V1816    smsa
ren V1806   split
ren V1809    fchg
ren V1839   hours
ren V1868   fsize
ren V1802      id
*ren V1942     age
*ren V1944    agew
ren V1943     sex
ren V1945    kids
ren V1983   empst
ren V1986    self
ren V2165   newhd
ren V2202    race
ren V2226       y
ren V1897      ly
ren V1899     wly
ren V1906    tyhw
ren V1924   tyoth
ren V1927   troth
ren V1922    trhw
ren V2279    avhy
ren V2072   marit
ren V2321  weight
ren V2197    educ
gen weduc=.
ren V1876    food
ren V1886    fout
gen          ftax=V1910+V1926 if V1910!=. & V1926!=.
replace 	 ftax=V1910       if V1910!=. & V1926==.
replace      ftax=V1926       if V1910==. & V1926!=.
drop V1910 V1926
gen         asset=.
gen          trhf=.
gen year=1970
tempfile fam70
save `fam70',replace

use "$rawdata/fam1972", clear
#delimit;
keep V2403 V2406 V2407 V2410 V2439 V2468 V2402 V2542 V2543 V2544 V2545 V2581 V2584 V2791 V2828 
     V2852 V2498 V2500 V2507 V2525 V2528 V2523 V2581
     V2906 V2670 V2968 V2823 V2476 V2480 V2511 V2527 V2449 V2478 V2825 V2708 V2718 V2429 V2423 V2434 V2557 V2493 V2687 V2533 V2822;
#delimit cr
ren	V2822	father_educ
ren	V2533	id67
ren V2493   wages
ren V2434    util 
ren V2557   ncars
ren V2423   house 
ren V2429    rent
ren V2718   disab
ren V2708  outkid
ren V2825     vet
ren V2478   fstmp
ren V2449   hourw
ren V2403   state 
ren V2406    smsa
ren V2407   split
ren V2410    fchg
ren V2439   hours
ren V2468   fsize
ren V2402      id
*ren V2542     age
*ren V2544    agew
ren V2543     sex
ren V2545    kids
ren V2581   empst
ren V2584    self
ren V2791   newhd
ren V2828    race
ren V2852       y
ren V2498      ly
ren V2500     wly
ren V2507    tyhw
ren V2525   tyoth
ren V2528   troth
ren V2523    trhw
ren V2906    avhy
ren V2670   marit
ren V2968  weight
ren V2823    educ
ren	V2687	weduc
ren V2476    food
ren V2480    fout

gen     ftax=V2511+V2527 if V2511!=. & V2527!=.
replace ftax=V2511       if V2511!=. & V2527==.
replace ftax=V2527       if V2511==. & V2527!=.
drop V2511 V2527
gen asset=.
gen trhf=.
gen year=1971
tempfile fam71
save `fam71',replace


use "$rawdata/fam1973", clear
#delimit;
keep V3003 V3006 V3007 V3010 V3027 V3017 V3002 V3095 V3096 V3097 V3098 V3114 V3117 V3217 V3300 
     V3256 V3051 V3053 V3060 V3078 V3081 V3076 V3114
     V3275 V3181 V3301 V3241 V3064 V3080 V3035 V3243 V3211 V3244 V3023 V3021 V3046 V3216 V3085 V3240;
#delimit cr   
ren	V3240	father_educ
ren	V3085	id67
ren V3046   wages
gen          util=.
gen         ncars=.
ren V3021   house
ren V3023    rent
ren V3244   disab
ren V3211  outkid
ren V3243     vet
gen        fstmp=.
ren V3035   hourw
ren V3003   state
ren V3006    smsa
ren V3007   split
ren V3010    fchg
ren V3027   hours
ren V3017   fsize
ren V3002      id
*ren V3095     age
*ren V3097    agew
ren V3096     sex
ren V3098    kids
ren V3114   empst
ren V3117    self
ren V3217   newhd
ren V3300    race
ren V3256       y
ren V3051      ly
ren V3053     wly
ren V3060    tyhw
ren V3078   tyoth
ren V3081   troth
ren V3076    trhw
ren V3275    avhy
ren V3181   marit
ren V3301  weight
ren V3241    educ
ren	V3216	weduc


gen food=.
gen fout=.

gen     ftax=V3064+V3080 if V3064!=. & V3080!=.
replace ftax=V3064       if V3064!=. & V3080==.
replace ftax=V3080       if V3064==. & V3080!=.
drop V3064 V3080
gen asset=.
gen trhf=.
gen year=1972
tempfile fam72
save `fam72',replace

use "$rawdata/fam1974", clear
#delimit;
keep V3403 V3406 V3407 V3410 V3423 V3437 V3402 V3508 V3509 V3510 V3511 V3528 V3532 V3639 V3720 
     V3676 V3463 V3465 V3472 V3490 V3493 V3488 V3528
     V3695 V3598 V3721 V3663 V3441 V3445 V3476 V3492 V3431 V3443 V3665 V3630 V3666 V3419 V3417 V3458 V3638 V3497 V3662 V3608 V3620 V3610;
#delimit cr 
ren	V3610	wexp_18

ren	V3620	exp_18
 
ren	V3608	wfather_educ

ren	V3662	father_educ
ren	V3497	id67
ren V3458 wages
gen util=.
gen ncars=.
ren V3417 house
ren V3419 rent
ren V3666 disab
ren V3630 outkid
ren V3665 vet
ren V3443   fstmp
ren V3431   hourw
ren V3403   state
ren V3406    smsa
ren V3407   split
ren V3410    fchg
ren V3423   hours
ren V3437   fsize
ren V3402      id
*ren V3508     age
*ren V3510    agew
ren V3509     sex
ren V3511    kids
ren V3528   empst
ren V3532    self
ren V3639   newhd
ren V3720    race
ren V3676       y
ren V3463      ly
ren V3465     wly
ren V3472    tyhw
ren V3490   tyoth
ren V3493   troth
ren V3488    trhw
ren V3695    avhy
ren V3598   marit
ren V3721  weight
ren V3663    educ
ren	V3638	weduc

ren V3441    food
ren V3445    fout

gen         ftax=V3476+V3492 if V3476!=. & V3492!=.
replace     ftax=V3476       if V3476!=. & V3492==.
replace     ftax=V3492       if V3476==. & V3492!=.
drop V3476 V3492
gen 	     asset=.
gen         trhf=.
gen year=1973
tempfile fam73
save `fam73',replace


use "$rawdata/fam1975", clear
#delimit;
keep V3803 V3806 V3807 V3810 V3823 V3837 V3802 V3921 V3922 V3923 V3924 V3967 V3970 V4114 V4204 
     V4154 V3863 V3865 V3872 V3891 V3905 V3889 V3967 V4093 V4102
     V4174 V4053 V4224 V4198 V3841 V3853 V3876 V3893 V3831 V3851 V4140 V4076 V4145 V3819 V3817 V3931 V3858 V4199 V3909 V4138 V4108 V4141 V4110; 
#delimit cr  
ren	V4110	wexp_18

ren	V4141	exp_18

ren	V4108	wfather_educ
   
ren	V4138	father_educ
ren	V3909	id67
rename	V4102	w_schooling
rename	V4093	schooling
ren V3858   wages
gen          util=.    
ren V3931   ncars
ren V3817   house
ren V3819    rent
ren V4145   disab
ren V4076  outkid
ren V4140     vet
ren V3851   fstmp
ren V3831   hourw
ren V3803   state
ren V3806    smsa
ren V3807   split
ren V3810    fchg
ren V3823   hours
ren V3837   fsize
ren V3802      id
*ren V3921     age
*ren V3923    agew
ren V3922     sex
ren V3924    kids
ren V3967   empst
ren V3970    self
ren V4114   newhd
ren V4204    race
ren V4154       y
ren V3863      ly
ren V3865     wly
ren V3872    tyhw
ren V3891   tyoth
ren V3905   troth
ren V3889    trhw
ren V4174    avhy
ren V4053   marit
ren V4224  weight
ren V4198    educ
ren	V4199	weduc
ren V3841    food
ren V3853    fout

gen          ftax=V3876+V3893 if V3876!=. & V3893!=.
replace 	 ftax=V3876       if V3876!=. & V3893==.
replace 	 ftax=V3893       if V3876==. & V3893!=.
drop V3876 V3893
gen 		asset=.
gen 		 trhf=.
gen year=1974
tempfile fam74
save `fam74',replace


use "$rawdata/fam1976", clear
#delimit;
keep V4303 V4306 V4307 V4310 V4332 V4346 V4302 V4436 V4437 V4438 V4439 V4458 V4461 V4658 V5096 
     V5029 V5031 V4379 V4386 V4406 V4419 V4404 V4458 V4841 V4684 V4695
     V5050 V4603 V5099 V5074 V4354 V4368 V4390 V4409 V5076 V4344 V4364 V4683 V4620 V4625 V4326 V4318 V4446 V4373 V5075 V4423 V4681 V4753 V4630 V4989 V4609 V4768;
#delimit cr 
ren	V4768	whousework_wk

ren	V4609	housework_wk

ren	V4989	wexp_18

ren	V4630	exp_18
ren	V4753	wfather_educ
  
ren	V4681	father_educ
ren	V4423	id67
rename	V4695	w_schooling
rename	V4684	schooling
rename	V4841	w_empl_status
ren V4373 wages
gen 		 util=.   
ren V4446   ncars
ren V4318   house
ren V4326    rent
ren V4625   disab
ren V4620  outkid
ren V4683     vet
ren V4364   fstmp
ren V4344   hourw
ren V4303   state
ren V4306    smsa
ren V4307   split
ren V4310    fchg
ren V4332   hours
ren V4346   fsize
ren V4302      id
*ren V4436     age
*ren V4438    agew
ren V4437     sex
ren V4439    kids
ren V4458   empst
ren V4461    self
ren V4658   newhd
ren V5096    race
ren V5029       y
ren V5031      ly
ren V4379     wly
ren V4386    tyhw
ren V4406   tyoth
ren V4419   troth
ren V4404    trhw
ren V5050    avhy
ren V4603   marit
ren V5099  weight
ren V5074    educ
ren	V5075	weduc

ren V4354    food
ren V4368    fout

gen          ftax=V4390+V4409  if V4390!=. & V4409!=.
replace 	 ftax=V4390        if V4390!=. & V4409==.
replace 	 ftax=V4409        if V4390==. & V4409!=.
replace 	 ftax=ftax-V5076 if V5076!=.
gen 		asset=.
gen 		 trhf=.
drop V4390 V4409 V5076
gen year=1975
tempfile fam75
save `fam75',replace


use "$rawdata/fam1977", clear
#delimit;
keep V5203 V5206 V5207 V5210 V5232 V5254 V5202 V5350 V5351 V5352 V5353 V5373 V5376 V5578 V5662 
     V5626 V5627 V5289 V5297 V5318 V5332 V5316
     V5631 V5650 V5665 V5647 V5271 V5273 V5373 V5608 V5567
     V5301 V5321 V5649 V5244 V5277 V5603 V5555 V5560 V5225 V5217 V5231 V5360 V5283 V5648 V5336 V5601 V5572 V5604 V5574 V5535 V5534;
#delimit cr
ren	V5534	whousework_wk

ren	V5535	housework_wk
ren	V5574	wexp_18

ren	V5604	exp_18

ren	V5572	wfather_educ
ren	V5601	father_educ
ren	V5336	id67
rename	V5567	w_schooling
rename	V5608	schooling
ren V5283   wages
ren V5231    util 
ren V5360   ncars
ren V5217   house
ren V5225    rent
ren V5560   disab
ren V5555  outkid
ren V5603     vet
ren V5277   fstmp
ren V5244   hourw
ren V5203   state
ren V5206    smsa
ren V5207   split
ren V5210    fchg
ren V5232   hours
ren V5254   fsize
ren V5202      id
*ren V5350     age
*ren V5352    agew
ren V5351     sex
ren V5353    kids
ren V5373   empst
ren V5376    self
ren V5578   newhd
ren V5662    race
ren V5626       y
ren V5627      ly
ren V5289     wly
ren V5297    tyhw
ren V5318   tyoth
ren V5332   troth
ren V5316    trhw
ren V5631    avhy
ren V5650   marit
ren V5665  weight
ren V5271    food
ren V5273    fout
ren V5647    educ
ren	V5648	weduc


gen     ftax=V5301+V5321  if V5301!=. & V5321!=.
replace ftax=V5301        if V5301!=. & V5321==.
replace ftax=V5321        if V5301==. & V5321!=.
replace ftax=ftax-V5649 if V5649!=.
drop V5301 V5321 V5649
gen asset=.
gen trhf=.
gen year=1976
tempfile fam76
save `fam76',replace


use "$rawdata/fam1978", clear
#delimit;
keep V5703 V5706 V5707 V5710 V5731 V5755 V5702 V5850 V5851 V5852 V5853 V5782 V5875 V6127 V6209 
     V6173 V6174 V5788 V5796 V5817 V5831 V5815 V5872 V6157 V6116
     V6178 V6197 V6212 V6194 V5770 V5772 V5800 V5820 V6196 V5743 V5815 V5831 V5776 V6152 V6097 V6102 V5723 V5717 V5729 V5860 V5872 V6195 V5835 V6150 V6121 V6153 V6123 V6073 V6072;
#delimit cr  
ren	V6072	whousework_wk

ren	V6073	housework_wk


ren	V6123	wexp_18

ren	V6153	exp_18

ren	V6121	wfather_educ

        
ren	V6150	father_educ

ren	V5835	id67
rename	V6116	w_schooling
rename	V6157	schooling
ren V5782   wages
ren V5729    util 
ren V5860   ncars
ren V5717   house
ren V5723    rent
ren V6102   disab
ren V6097  outkid
ren V6152     vet
ren V5776   fstmp
ren V5815    trhw 
ren V5743   hourw
ren V5703   state
ren V5706    smsa
ren V5707   split
ren V5710    fchg
ren V5731   hours
ren V5755   fsize
ren V5702      id
*ren V5850     age
*ren V5852    agew
ren V5851     sex
ren V5853    kids
ren V5872   empst
ren V5875    self
ren V6127   newhd
ren V6209    race
ren V6173       y
ren V6174      ly
ren V5788     wly
ren V5796    tyhw
ren V5817   tyoth
ren V5831   troth
ren V6178    avhy
ren V6197   marit
ren V6212  weight
ren V6194    educ
ren	V6195	weduc


ren V5770    food
ren V5772    fout
gen     ftax=V5800+V5820  if V5800!=. & V5820!=.
replace ftax=V5800        if V5800!=. & V5820==.
replace ftax=V5820        if V5800==. & V5820!=.
replace ftax=ftax-V6196 if V6196!=.
drop V5800 V5820 V6196
gen asset=.
gen year=1977
tempfile fam77
save `fam77',replace


use "$rawdata/fam1979", clear
gen truncy	=V6766==99999												/*From now on, define {0,1} for topcoded income*/
gen trunca	=V6400==99999|V6401==99999|V6402==9999 |V6404==99999|V6400==-9999|V6402==-999		/*From now on, define {0,1} for topcoded financial income*/
#delimit;
keep V6303 V6306 V6307 V6310 V6336 V6361 V6302 V6462 V6463 V6464 V6465 V6492 V6493 V6724 V6802 
     V6766 V6767 V6398 V6408 V6428 V6442 V6426 V6492
     V6771 V6790 V6805 V6787 V6376 V6378 V6411 V6431 V6789 V6348
     V6400-V6406 V6430 V6426 V6442 V6382 V6749 V6690 V6710 V6326 V6319 V6332 V6473 V6391 V6495 V6496 V6422 V6440 trunc*
	 V6409 V6422 V6440 V6788 V6591 V6754 V6713 V6446 V6747 V6718 V6750 V6720 V6664 V6663
	 ;
#delimit cr
ren	V6663	whousework_wk

ren	V6664	housework_wk

ren	V6720	wexp_18

ren	V6750	exp_18

ren	V6718	wfather_educ

ren	V6747	father_educ
ren	V6446	id67
gen     aoth=0            if V6430==0
replace aoth=V6428*0.01   if V6430==1
replace aoth=V6428*0.0375 if V6430==2
replace aoth=V6428*0.085  if V6430==3
replace aoth=V6428*0.1125 if V6430==4
replace aoth=V6428*0.2    if V6430==5
replace aoth=V6428*0.3    if V6430==6
replace aoth=V6428*0.35   if V6430==7
replace aoth=V6428*0.5    if V6430==8
rename	V6713	w_schooling
rename	V6591	w_empl_status
ren V6495 unionj  
ren V6496 unioni  
gen asset=V6400+V6401+V6402+V6403+V6404+V6405+V6406+aoth
drop      V6400-V6406 aoth
rename	V6754	schooling
ren V6391   wages
ren V6332    util
ren V6473   ncars
ren V6319   house
ren V6326    rent
ren V6710   disab
ren V6690  outkid
ren V6749     vet
ren V6382   fstmp
ren V6348   hourw
ren V6303   state
ren V6306    smsa
ren V6307   split
ren V6310    fchg
ren V6336   hours
ren V6361   fsize
ren V6302      id
*ren V6462     age
*ren V6464    agew
ren V6463     sex
ren V6465    kids
ren V6492   empst
ren V6493    self
ren V6724   newhd
ren V6802    race
ren V6766       y
ren V6767      ly
ren V6398     wly
ren V6408    tyhw
ren V6428   tyoth
ren V6442   troth
ren V6426    trhw
ren V6409 giveamt
ren V6422 increlh
ren V6440 increlofum
ren V6771    avhy
ren V6790   marit
ren V6805  weight
ren V6787    educ
ren	V6788	weduc


ren V6376    food
ren V6378    fout
gen     	 ftax=V6411+V6431  if V6411!=. & V6431!=.
replace 	 ftax=V6411        if V6411!=. & V6431==.
replace 	 ftax=V6431        if V6411==. & V6431!=.
replace 	 ftax=ftax-V6789 if V6789!=.
drop V6411 V6431 V6789 V6430
gen year=1978
tempfile fam78
save `fam78',replace


use "$rawdata/fam1980", clear
gen truncy	=V7412==999999
gen trunca	=V6992==9999 |V6994==99999|V6990==-9999|V6991==-9999|V6992==-999
#delimit;
keep V6903 V6906 V6907 V6910 V6934 V6959 V6902 V7067 V7068 V7069 V7070 V7095 V7096 V7357 V7447 
     V7412 V7413 V6988 V6998 V7033 V7046 V7016
     V7417 V7435 V7451 V7433 V6972 V6974 V7399 V7411 V6946
     V6990-V6996 V7035 V7016 V7046 V6976 V7382 V7293 V7343 V6925 V6917 V6931 V7078 V6981 trunc* 
	 V7098 V7099 V7012 V7044 V6999 V7012 V7044 V7434 V7095 V7193 V7387 V7346 V7050 V7380 V7351 V7383 V7353 V7266 V7265
	 ;
#delimit cr
ren	V7265	whousework_wk

ren	V7266	housework_wk
 
ren	V7353	wexp_18

ren	V7383	exp_18

ren	V7351	wfather_educ

ren	V7380	father_educ
         
ren	V7050	id67
gen     aoth=0            if V7035==0
replace aoth=V7033*0.01   if V7035==1
replace aoth=V7033*0.0375 if V7035==2
replace aoth=V7033*0.085  if V7035==3
replace aoth=V7033*0.1125 if V7035==4
replace aoth=V7033*0.2    if V7035==5
replace aoth=V7033*0.3    if V7035==6
replace aoth=V7033*0.35   if V7035==7
replace aoth=V7033*0.5    if V7035==8
gen asset=V6990+V6991+V6992+V6993+V6994+V6995+V6996+aoth
drop      V6990-V6996 aoth
rename	V7387	schooling
rename	V7193	w_empl_status
rename	V7346	w_schooling
ren V7098 unionj  
ren V7099 unioni  
ren V6981 	wages
ren V6931    util 
ren V7078   ncars
ren V6917 	house
ren V6925 	 rent
ren V7343 	disab
ren V7293  outkid
ren V7382     vet
ren V6976   fstmp
ren V6946   hourw
ren V6903   state
ren V6906    smsa
ren V6907   split
ren V6910    fchg
ren V6934   hours
ren V6959   fsize
ren V6902      id
*ren V7067     age
*ren V7069    agew
ren V7068     sex
ren V7070    kids
ren V7095   empst
ren V7096    self
ren V7357   newhd
ren V7447    race
ren V7412       y
ren V7413      ly
ren V6988     wly
ren V6998    tyhw
ren V7033   tyoth
ren V7046   troth
ren V7016    trhw
ren V7417    avhy
ren V6999 giveamt
ren V7012 increlh
ren V7044 increlofum
ren V7435   marit
ren V7451  weight
ren V7433    educ
ren	V7434	weduc

ren V6972    food
ren V6974    fout
gen     	 ftax=V7399+V7411 if V7399!=. & V7411!=.
replace 	 ftax=V7399       if V7399!=. & V7411==.
replace 	 ftax=V7411       if V7399==. & V7411!=.
drop V7399 V7411 V7035
gen year=1979
tempfile fam79
save `fam79',replace


use "$rawdata/fam1981", clear
gen truncy	=V8065==9999999
gen trunca	=V7586==99999|V7587==9999|V7584==-9999
#delimit;
keep V7503 V7506 V7507 V7510 V7530 V7551 V7502 V7658 V7659 V7660 V7661 V7706 V7707 V8009 V8099 
     V8065 V8066 V7580 V7590 V7625 V7638 V7608 V7706
     V8069 V8087 V8103 V8085 V7564 V7566 V8052 V8064 V7540
     V7582-V7588 V7627 V7608 V7638 V7568 V8034 V7993 V7974 V7525 V7517 V7699 V7669 V7573 trunc* 
	 V7709 V7710 V7604 V7636 V7591 V7604 V7636 V8086 V7879 V8039 V7998 V7642 V8032 V8003 V8035 V8005 V7957 V7956
	 ;
#delimit cr
ren	V7956	whousework_wk

ren	V7957	housework_wk

ren	V8005	wexp_18

ren	V8035	exp_18

ren	V8003	wfather_educ

ren	V8032	father_educ

ren	V7642	id67
rename	V7998	w_schooling
rename	V8039	schooling
rename	V7879	w_empl_status
ren V7709 unionj  
ren V7710 unioni  
gen     aoth=0            if V7627==0
replace aoth=V7625*0.01   if V7627==1
replace aoth=V7625*0.0375 if V7627==2
replace aoth=V7625*0.085  if V7627==3
replace aoth=V7625*0.1125 if V7627==4
replace aoth=V7625*0.2    if V7627==5
replace aoth=V7625*0.3    if V7627==6
replace aoth=V7625*0.35   if V7627==7
replace aoth=V7625*0.5    if V7627==8
gen asset=V7582+V7583+V7584+V7585+V7586+V7587+V7588+aoth
drop V7582-V7588 aoth    
ren V7573   wages
ren V7699    util 
ren V7669   ncars
ren V7517   house
ren V7525    rent
ren V7974   disab
ren V7993  outkid
ren V8034 	  vet
ren V7568   fstmp
ren V7540   hourw
ren V7503   state
ren V7506    smsa
ren V7507   split
ren V7510    fchg
ren V7530   hours
ren V7551   fsize
ren V7502      id
*ren V7658     age
*ren V7660    agew
ren V7659     sex
ren V7661    kids
ren V7706   empst
ren V7707    self
ren V8009   newhd
ren V8099    race
ren V8065       y
ren V8066      ly
ren V7580     wly
ren V7590    tyhw
ren V7625   tyoth
ren V7638   troth
ren V7608    trhw
ren V8069    avhy
ren V7591 giveamt
ren V7604 increlh
ren V7636 increlofum
ren V8087   marit
ren V8103  weight
ren V8085    educ
ren	V8086	weduc


ren V7564    food
ren V7566    fout
gen     	 ftax=V8052+V8064 if V8052!=. & V8064!=.
replace 	 ftax=V8052       if V8052!=. & V8064==.
replace 	 ftax=V8064       if V8052==. & V8064!=.
drop V8052 V8064 V7627
gen year=1980
tempfile fam80
save `fam80',replace

use "$rawdata/fam1982", clear
gen truncy	=V8689==999999
gen trunca	=V8275==99999|V8276==99999|V8277==99999|V8277==-9999|V8278==99999|V8279==99999|V8280==9999 |V8281==99999
#delimit;
keep V8203 V8206 V8207 V8210 V8228 V8249 V8202 V8352 V8353 V8354 V8355 V8374 V8375 V8633 V8723 
     V8689 V8690 V8273 V8283 V8318 V8331 V8301
     V8693 V8711 V8727 V8709 V8256 V8258 V8676 V8688 V8238 V8622
     V8275-V8281 V8320 V8301 V8331 V8260 V8658 V8612 V8616 V8221 V8217 V8225 V8358 V8265 trunc* 
	 V8377 V8378 V8297 V8329 V8284 V8297 V8329 V8710 V8374 V8538 V8663 V8335 V8656 V8627 V8659 V8629
	 ;
#delimit cr  
ren	V8629	wexp_18

ren	V8659	exp_18

ren	V8627	wfather_educ

ren	V8656	father_educ
         
 ren	V8335	id67
 
gen     aoth=0            if V8320==0
replace aoth=V8318*0.01   if V8320==1
replace aoth=V8318*0.0375 if V8320==2
replace aoth=V8318*0.085  if V8320==3
replace aoth=V8318*0.1125 if V8320==4
replace aoth=V8318*0.2    if V8320==5
replace aoth=V8318*0.3    if V8320==6
replace aoth=V8318*0.35   if V8320==7
replace aoth=V8318*0.5    if V8320==8
gen asset=V8275+V8276+V8277+V8278+V8279+V8280+V8281+aoth
drop V8275-V8281 aoth
rename	V8538	w_empl_status
rename	V8663	schooling
rename	V8622	w_schooling

ren V8377 unionj  
ren V8378 unioni  
ren V8265   wages
ren V8225    util 
ren V8358   ncars
ren V8217   house
ren V8221    rent
ren V8616   disab
ren V8612  outkid
ren V8658     vet
ren V8260   fstmp
ren V8238   hourw
ren V8203   state
ren V8206    smsa
ren V8207   split
ren V8210    fchg
ren V8228   hours
ren V8249   fsize
ren V8202      id
*ren V8352     age
*ren V8354    agew
ren V8353     sex
ren V8355    kids
ren V8374   empst
ren V8375    self
ren V8633   newhd
ren V8723    race
ren V8689       y
ren V8690      ly
ren V8273     wly
ren V8283    tyhw
ren V8318   tyoth
ren V8331   troth
ren V8301    trhw
ren V8693    avhy
ren V8284 giveamt
ren V8297 increlh
ren V8329 increlofum
ren V8711   marit
ren V8727  weight
ren V8709    educ
ren	V8710	weduc


ren V8256    food
ren V8258    fout
gen     	 ftax=V8676+V8688 if V8676!=. & V8688!=.
replace 	 ftax=V8676       if V8676!=. & V8688==.
replace 	 ftax=V8688       if V8676==. & V8688!=.
drop V8676 V8688 V8320
gen year=1981
tempfile fam81
save `fam81',replace


use "$rawdata/fam1983", clear
gen truncy	=V9375==9999999
gen trunca	=V8883==999999|V8884==999999|V8885==99999 |V8885==-9999 |V8886==99999 |V8887==999999|V8888==99999 |V8889==99999
#delimit;
keep V8803 V8806 V8807 V8810 V8830 V8851 V8802 V8961 V8962 V8963 V8964 V9005 V9006 V9319 V9408 
     V9375 V9376 V8881 V8891 V8926 V8939 V8909
     V9379 V9419 V9433 V9395 V8864 V8866 V9362 V9374 V8840 V9349
     V8883-V8889 V8928 V8909 V8939 V8868 V9344 V9303 V9290 V8825 V8817 V8998 V8967 V8873 trunc* 
	 V9008 V9009 V8905 V8937 V8892 V8905 V8937 V9396 V9005 V9188 V9308 V8943 V9342 V9313 V9345 V9315 V9281 V9280
	 ;
#delimit cr 
ren	V9280	whousework_wk

ren	V9281	housework_wk

ren	V9315	wexp_18
ren	V9345	exp_18

ren	V9313	wfather_educ

ren	V9342	father_educ
      
ren	V8943	id67

rename	V9308	w_schooling
rename	V9349	schooling
rename	V9188	w_empl_status
ren V9008 unionj  
ren V9009 unioni  
gen asset=V8883+V8884+V8885+V8886+V8887+V8888+V8889+V8928
drop V8883-V8889 V8928  
ren V8873   wages
ren V8998    util
ren V8967   ncars
ren V8817   house
ren V8825    rent
ren V9290   disab
ren V9303  outkid
ren V9344     vet
ren V8868   fstmp
ren V8840   hourw
ren V8803   state
ren V8806    smsa
ren V8807   split
ren V8810    fchg
ren V8830   hours
ren V8851   fsize
ren V8802      id
*ren V8961     age
*ren V8963    agew
ren V8962     sex
ren V8964    kids
ren V9005   empst
ren V9006    self
ren V9319   newhd
ren V9408    race
ren V9375       y
ren V9376      ly
ren V8881     wly
ren V8891    tyhw
ren V8926   tyoth
ren V8939   troth
ren V8909    trhw
ren V9379    avhy
ren V8892 giveamt
ren V8905 increlh
ren V8937 increlofum
ren V9419   marit
ren V9433  weight
ren V9395    educ
ren	V9396	weduc


ren V8864    food
ren V8866    fout
gen          ftax=V9362+V9374 if V9362!=. & V9374!=.
replace      ftax=V9362       if V9362!=. & V9374==.
replace      ftax=V9374       if V9362==. & V9374!=.
drop V9362 V9374
gen year=1982
tempfile fam82
save `fam82',replace


use "$rawdata/fam1984", clear
gen truncy	=V11022==999999
gen trunca	=V10265==999999|V10266==999999|V10267==99999 |V10268==99999 |V10270==999999|V10272==999999|V10274==99999 |V10275==999999|V10276==-9999
#delimit;
keep V10003 V10006 V10007 V10010 V10037 V10222 V10002 V10419 V10420 V10421 V10422 V10453 V10456 V10966 V11055 
     V11022 V11023 V10263 V10277 V10382 V10396 V10305
     V11026 V11065 V11079 V11042 V10235 V10237 V11009 V11021 V10131
     V10265-V10268 V10270 V10272 V10274 V10275 V10384 V10305 V10396 V10239 V10991 V10894 
	 V10879 V10026 V10018 V10030 V10430 V10256 trunc*  
     V10458 V10459 V10300 V10394 V10278 V10300 V10394 V11043 V10453 V10671 V10996 V10955 V10400	 V10989 V10960 V10992 V10962 V10867 V10866

	 ;
#delimit cr
ren	V10866	whousework_wk

ren	V10867	housework_wk

ren	V10962	wexp_18
ren	V10992	exp_18
ren	V10960	wfather_educ

ren	V10989	father_educ

ren	V10400	id67
rename	V10671	w_empl_status
rename	V10996	schooling
rename	V10955	w_schooling

ren V10458 unionj 
ren V10459 unioni 
gen asset=V10265+V10266+V10267+V10268+V10270+V10272+V10274+V10275+V10384
drop V10265-V10268 V10270 V10272 V10274 V10275 V10384
ren V10256   wages
ren V10030    util 
ren V10430   ncars
ren V10018   house
ren V10026    rent
ren V10879   disab
ren V10894  outkid
ren V10991     vet
ren V10239   fstmp
ren V10131   hourw
ren V10003   state
ren V10006    smsa
ren V10007   split
ren V10010    fchg
ren V10037   hours
ren V10222   fsize
ren V10002      id
*ren V10419     age
*ren V10421    agew
ren V10420     sex
ren V10422    kids
ren V10453   empst
ren V10456    self
ren V10966   newhd
ren V11055    race
ren V11022       y
ren V11023      ly
ren V10263     wly
ren V10277    tyhw
ren V10382   tyoth
ren V10396   troth
ren V10305    trhw
ren V11026    avhy
ren V10278 giveamt
ren V10300 increlh
ren V10394 increlofum
ren V11065   marit
ren V11079  weight
ren V11042    educ
ren	V11043	weduc


ren V10235    food
ren V10237    fout
gen           ftax=V11009+V11021 if V11009!=. & V11021!=.
replace       ftax=V11009       if V11009!=. & V11021==.
replace       ftax=V11021       if V11009==. & V11021!=.
drop V11009 V11021
gen year=1983
tempfile fam83
save `fam83',replace



use "$rawdata/fam1985", clear
gen truncy	=V12371==999999
gen trunca	=V11406==999999|V11407==999999|V11408==99999 |V11406==-99999|V11407==-99999|V11408==-9999 |V11409==99999 |V11412==999999|V11414==999999| ///		
		 V11416==999999|V11417==999999
#delimit;
keep V11103 V11106 V11107 V11112 V11146 V11364 V11102 V11606 V11607 V11608 V11609 V11637 V11640 V11906 V11938 
     V12371 V12372 V11404 V11419 V11561 V11577 V11461
     V12377 V12426 V12446 V12400 V11375 V11377 V12358 V12370 V11258 V11637
     V11406-V11409 V11412  V11414  V11416 V11417 V11563 V11461 V11577 V11379 V11940 V11896 V11993 V11133 V11125 V11137 V11635 V11397 trunc* 
     V11649 V11650 V11445 V11457 V11574 V11420 V11421 V11422 V11445 V11457 V11574 V12401 V12000 V11581 V11922 V12277 V11739 V12102 V11982 V12337
;
#delimit cr
ren	V12337	whousework_wk

ren	V11982	housework_wk

ren	V12102	wexp_18

ren	V11739	exp_18


ren	V12277	wfather_educ

ren	V11922	father_educ

ren	V11581	id67
ren V11649 unionj 
ren V11650 unioni 
rename	V12000	w_empl_status

gen asset=V11406+V11407+V11408+V11409+V11412+V11414+V11416+V11417+V11563
drop 	V11406-V11409 V11412  V11414  V11416 V11417 V11563
ren V11397   wages
ren V11137    util 
ren V11635   ncars
ren V11125   house
ren V11133    rent
ren V11993   disab
ren V11896  outkid
ren V11940     vet
ren V11379   fstmp
ren V11258   hourw
ren V11103   state
ren V11106    smsa
ren V11107   split
ren V11112    fchg
ren V11146   hours
ren V11364   fsize
ren V11102      id
*ren V11606     age
*ren V11608    agew
ren V11607     sex
ren V11609    kids
ren V11637   empst
ren V11640    self
ren V11906   newhd
ren V11938    race
ren V12371       y
ren V12372      ly
ren V11404     wly
ren V11419    tyhw
ren V11561   tyoth
ren V11577   troth
ren V11461    trhw
ren V12377    avhy
ren V11420 giveamt
ren V11421 givechsup
ren V11422 givealim
ren V11445 increlh
ren V11457 increlw
ren V11574 increlofum
ren V12426   marit
ren V12446  weight
ren V12400    educ
ren	V12401	weduc

ren V11375    food
ren V11377    fout
gen           ftax=V12358+V12370 if V12358!=. & V12370!=.
replace       ftax=V12358       if V12358!=. & V12370==.
replace       ftax=V12370       if V12358==. & V12370!=.
drop V12358 V12370
gen year=1984
tempfile fam84
save `fam84',replace



use "$rawdata/fam1986", clear
gen truncy	=V13623==999999
gen trunca	=V12806==-99999|V12807==-9999
#delimit;
keep V12503 V12506 V12507 V12510 V12545 V12763 V12502 V13011 V13012 V13013 V13014 V13046 V13049 V13533 V13565 
     V13623 V13624 V12803 V12818 V12968 V12984 V12868
     V13629 V13665 V13687 V13640 V12774 V12776 V13610 V13622 V12657 V13046
     V12805-V12808  V12811  V12813  V12815 V12816 V12970 V12868 V12984 V12778 V13567 V13407 V13427 V12532 V12524 V12536 V13044 V12796 trunc*
	 V13052 V13053 V12844 V12864 V12981 V12819 V12820 V12821 V12844 V12864 V12981 V13641 V13225 V12988 V13549 V13485 V13605 V13531 V13394 V13393
;
#delimit cr 
ren	V13393	whousework_wk

ren	V13394	housework_wk
ren	V13531	wexp_18

ren	V13605	exp_18

ren	V13485	wfather_educ

ren	V13549	father_educ

ren	V12988	id67

ren V13052 unionj 
ren V13053 unioni 
rename	V13225	w_empl_status
gen asset=V12805+V12806+V12807+V12808+V12811+V12813+V12815+V12816+V12970
drop V12805-V12808  V12811  V12813  V12815 V12816 V12970
ren V12796   wages
ren V12536    util 
ren V13044   ncars
ren V12524   house
ren V12532    rent
ren V13427   disab
ren V13407  outkid
ren V13567     vet
ren V12778   fstmp
ren V12657   hourw
ren V12503   state
ren V12506    smsa
ren V12507   split
ren V12510    fchg
ren V12545   hours
ren V12763   fsize
ren V12502      id
*ren V13011     age
*ren V13013    agew
ren V13012     sex
ren V13014    kids
ren V13046   empst
ren V13049    self
ren V13533   newhd
ren V13565    race
ren V13623       y
ren V13624      ly
ren V12803     wly
ren V12818    tyhw
ren V12968   tyoth
ren V12984   troth
ren V12868    trhw
ren V13629    avhy
ren V12819 giveamt
ren V12820 givechsup
ren V12821 givealim
ren V12844 increlh
ren V12864 increlw
ren V12981 increlofum
ren V13665   marit
ren V13687  weight
ren V13640    educ
ren	V13641	weduc


ren V12774    food
ren V12776    fout
gen           ftax=V13610+V13622 if V13610!=. & V13622!=.
replace       ftax=V13610       if V13610!=. & V13622==.
replace       ftax=V13622       if V13610==. & V13622!=.
drop V13610 V13622
gen year=1985
tempfile fam85
save `fam85',replace


use "$rawdata/fam1987", clear
gen truncy=V14670==999999
gen trunca=V13909==-9999
#delimit;
keep V13703 V13706 V13707 V13710 V13745 V13867 V13702 V14114 V14115 V14116 V14117 V14146 V14149 V14580 V14612 
     V14670 V14671 V13905 V13920 V14070 V14086 V13970
     V14676 V14712 V14737 V14687 V13876 V13878 V14657 V14669 V13809
     V13907-V13910 V13913 V13915 V13917 V13918 V14072 V13970 V14086 V13880 V14614 V14504 V14515 V13732 V13724 V13736 V13898 trunc*
     V14152 V14153 V13946 V13966 V14083 V14146
	 V13921 V13922 V13923 V13946 V13966 V14688 V14321 V14090 V14596 V14532 V14652 V14578 V14486 V14485
;
#delimit cr
ren	V14485	whousework_wk

ren	V14486	housework_wk

ren	V14578	wexp_18

ren	V14652	exp_18
ren	V14532	wfather_educ

ren	V14596	father_educ

ren	V14090	id67

rename	V14321	w_empl_status
ren V14152 unionj 
ren V14153 unioni 
gen asset=V13907+V13908+V13909+V13910+V13913+V13915+V13917+V13918+V14072
drop V13907 V13908 V13909 V13910 V13913 V13915 V13917 V13918 V14072
gen  ncars=.
ren V13898   wages
ren V13736    util
ren V13724   house
ren V13732    rent
ren V14515   disab
ren V14504  outkid
ren V14614     vet
ren V13880   fstmp
ren V13809   hourw
ren V13703   state
ren V13706    smsa
ren V13707   split
ren V13710    fchg
ren V13745   hours
ren V13867   fsize
ren V13702      id
*ren V14114     age
*ren V14116    agew
ren V14115     sex
ren V14117    kids
ren V14146   empst
ren V14149    self
ren V14580   newhd
ren V14612    race
ren V14670       y
ren V14671      ly
ren V13905     wly
ren V13920    tyhw
ren V14070   tyoth
ren V14086   troth
ren V13970    trhw
ren V14676    avhy
ren V13921 giveamt
ren V13922 givechsup
ren V13923 givealim
ren V13946 increlh
ren V13966 increlw
ren V14083 increlofum
ren V14712   marit
ren V14737  weight
ren V14687    educ
ren	V14688	weduc


ren V13876    food
ren V13878    fout
gen           ftax=V14657+V14669 if V14657!=. & V14669!=.
replace       ftax=V14657        if V14657!=. & V14669==.
replace       ftax=V14669        if V14657==. & V14669!=.
drop V14657 V14669
gen year=1986
tempfile fam86
save `fam86',replace


use "$rawdata/fam1988", clear
gen truncy=V16144==9999999
gen trunca=V14924==-9999
#delimit;
keep V14803 V14806 V14807 V14810 V14835 V14889 V14802 V15130 V15131 V15132 V15133 V15154 V15157 V16054 V16086 
     V16144 V16145 V14920 V14935 V15085 V15101 V14985
     V16150 V16187 V16208 V16161 V16131 V16143 V14865
     V14922-V14925 V14928 V14930 V14932 V14933 V15087 V14985 V15101 V14895 V16088 V15779 V15994 V14824 V14913 trunc*
     V15160 V15161 V14961 V14981 V15098  V15154
	 V14936 V14937 V14938 V14981 V15098 V16162 V15456 V15105 V16070 V16006 V16126 V16052 V15759 V15758
;
#delimit cr
ren	V15758	whousework_wk

ren	V15759	housework_wk

ren	V16052	wexp_18

ren	V16126	exp_18

ren	V16006	wfather_educ

ren	V16070	father_educ

ren	V15105	id67

rename	V15456	w_empl_status
ren V15160 unionj
ren V15161 unioni 

gen asset=V14922+V14923+V14924+V14925+V14928+V14930+V14932+V14933+V15087
drop V14922-V14925 V14928 V14930 V14932 V14933 V15087
gen  ncars=.
gen   util=.
gen    rent=.
ren V14913   wages
ren V14824   house
ren V15994   disab
ren V15779  outkid
ren V16088     vet
ren V14895   fstmp
ren V14865   hourw
ren V14803   state
ren V14806    smsa
ren V14807   split
ren V14810    fchg
ren V14835   hours
ren V14889   fsize
ren V14802      id
*ren V15130     age
*ren V15132    agew
ren V15131     sex
ren V15133    kids
ren V15154   empst
ren V15157    self
ren V16054   newhd
ren V16086    race
ren V16144       y
ren V16145      ly
ren V14920     wly
ren V14935    tyhw
ren V15085   tyoth
ren V15101   troth
ren V14985    trhw
ren V16150    avhy
ren V14936 giveamt
ren V14937 givechsup
ren V14938 givealim
ren V14961 increlh
ren V14981 increlw
ren V15098 increlofum
ren V16187   marit
ren V16208  weight
ren V16161    educ
ren	V16162	weduc


gen 		  food=.
gen 		  fout=.
gen           ftax=V16131+V16143 if V16131!=. & V16143!=.
replace       ftax=V16131        if V16131!=. & V16143==.
replace       ftax=V16143        if V16131==. & V16143!=.
drop V16131 V16143
gen year=1987
tempfile fam87
save `fam87',replace


use "$rawdata/fam1989", clear
gen truncy=V17533==9999999
gen trunca=V16424==-99999
#delimit;
keep V16303 V16306 V16307 V16310 V16335 V16389 V16302 V16631 V16632 V16633 V16634 V16655 V16658 V17451 V17483 
     V17533 V17534 V16420 V16435 V16585 V16601 V16485 
     V17536 V17565 V17612 V17545 V17528 V17532 V16365
     V16422-V16425 V16428 V16430 V16432 V16433 V16587 V16485 V16601 V16395 V17485 V17308 V17391 V16324 V16413 trunc* 
	 V16661 V16662 V16461 V16481 V16598 V16655
	 V16436 V16437 V16438 V16461 V16481 V16598 V17546 V16974 V16605 V17467 V17403 V17523 V17449 V17294 V17293
;
#delimit cr
ren	V17293	whousework_wk

ren	V17294	housework_wk

ren	V17449	wexp_18

ren	V17523	exp_18

ren	V17403	wfather_educ

ren	V17467	father_educ

ren	V16605	id67
rename	V16974	w_empl_status

ren V16661 unionj 
ren V16662 unioni 

gen asset=V16422+V16423+V16424+V16425+V16428+V16430+V16432+V16433+V16587
drop V16422-V16425 V16428 V16430 V16432 V16433 V16587
gen    rent=.
gen  ncars=.
gen   util=.
ren V16413   wages
ren V16324   house
ren V17391   disab
ren V17308  outkid
ren V17485     vet
ren V16395   fstmp
ren V16365   hourw
ren V16303   state
ren V16306    smsa
ren V16307   split
ren V16310    fchg
ren V16335   hours
ren V16389   fsize
ren V16302      id
*ren V16631     age
*ren V16633    agew
ren V16632     sex
ren V16634    kids
ren V16655   empst
ren V16658    self
ren V17451   newhd
ren V17483    race
ren V17533       y
ren V17534      ly
ren V16420     wly
ren V16435    tyhw
ren V16585   tyoth
ren V16601   troth
ren V16485    trhw
ren V17536    avhy
ren V16436 giveamt
ren V16437 givechsup
ren V16438 givealim
ren V16461 increlh
ren V16481 increlw
ren V16598 increlofum
ren V17565   marit
ren V17612  weight
ren V17545    educ
ren	V17546	weduc


gen food=.
gen fout=.
gen          ftax=V17528+V17532 if V17528!=. & V17532!=.
replace      ftax=V17528       if V17528!=. & V17532==.
replace      ftax=V17532       if V17528==. & V17532!=.
drop V17528 V17532
gen year=1988
tempfile fam88
save `fam88',replace


use "$rawdata/fam1990", clear
gen truncy=V18875==9999999
gen trunca=V17838==999999
#delimit;
keep V17703 V17706 V17707 V17710 V17744 V17798 V17702 V18049 V18050 V18051 V18052 V18093 V18096 V18782 V18814 
     V18875 V18878 V17836 V17851 V18001 V18017 V17901 
     V18887 V18916 V18943 V18898 V17807 V17809 V18862 V18874 V17774
     V17838-V17841 V17844 V17846 V17848 V17849 V18003 V17901 V18017 V17811 V18816 V18712 V18722 V17733 V17724 V17829 trunc*
	 V18099 V18100 V17877 V17897 V18014 V18093
	 V17852 V17853 V17854 V17877 V17897 V18014 V18899 V18395 V18021 V18798 V18734 V18854 V18780 V18698 V18697
;
#delimit cr
ren	V18697	whousework_wk
ren	V18698	housework_wk

ren	V18780	wexp_18
ren	V18854	exp_18


ren	V18734	wfather_educ

ren	V18798	father_educ
ren	V18021	id67
rename	V18395	w_empl_status

ren V18099 unionj 
ren V18100 unioni 

gen asset=V17838+V17839+V17840+V17841+V17844+V17846+V17848+V17849+V18003 
drop V17838-V17841 V17844 V17846 V17848 V17849 V18003
gen  ncars=.
gen   util=.
ren V17829   wages
ren V17724   house
ren V17733    rent
ren V18722   disab
ren V18712  outkid
ren V18816     vet
ren V17811   fstmp
ren V17774   hourw
ren V17703   state
ren V17706    smsa
ren V17707   split
ren V17710    fchg
ren V17744   hours
ren V17798   fsize
ren V17702      id
*ren V18049     age
*ren V18051    agew
ren V18050     sex
ren V18052    kids
ren V18093   empst
ren V18096    self
ren V18782   newhd
ren V18814    race
ren V18875       y
ren V18878      ly
ren V17836     wly
ren V17851    tyhw
ren V18001   tyoth
ren V18017   troth
ren V17901    trhw
ren V18887    avhy
ren V17852 giveamt
ren V17853 givechsup
ren V17854 givealim
ren V17877 increlh
ren V17897 increlw
ren V18014 increlofum
ren V18916   marit
ren V18943  weight
ren V18898    educ
ren	V18899	weduc
ren V17807    food
ren V17809    fout
replace V18862=. if V18862==999999
replace V18874=. if V18874==999999
gen          ftax=V18862+V18874 if V18862!=. & V18874!=.
replace      ftax=V18862        if V18862!=. & V18874==.
replace      ftax=V18874        if V18862==. & V18874!=.
drop V18862 V18874
gen year=1989
tempfile fam89
save `fam89',replace


use "$rawdata/fam1991", clear
gen truncy=V20175==999999
gen trunca=V19139==-99999|V19140==-9999
#delimit;
keep V19003 V19006 V19007 V19010 V19044 V19098 V19002 V19349 V19350 V19351 V19352 V19393 V19396 V20082 V20114 
     V20175 V20178 V19136 V19151 V19301 V19317 V19201 
     V20187 V20216 V20243 V20198 V19107 V19109 V20162 V20174 V19074
     V19138-V19141 V19144 V19146 V19148 V19149 V19303 V19201 V19317 V19111 V20116 V20012 V20022 V19033 V19024 V19129 trunc* 
	 V19399 V19400 V19177 V19197 V19314 V19393
	 V19152 V19153 V19154 V19177 V19197 V19314 V19695 V20198 V20199 V19321 V20098 V20034 V20154 V20080 V19998 V19997
;
#delimit cr
ren	V19997	whousework_wk


ren	V19998	housework_wk

ren	V20080	wexp_18

ren	V20154	exp_18

ren	V20034	wfather_educ

ren	V20098	father_educ


ren	V19321	id67
rename	V19695	w_empl_status
rename	V20198	schooling
rename	V20199	w_schooling

ren V19399 unionj 
ren V19400 unioni 

gen asset=V19138+V19139+V19140+V19141+V19144+V19146+V19148+V19149+V19303
drop V19138-V19141 V19144 V19146 V19148 V19149 V19303
gen  ncars=.
gen   util=.
ren V19129   wages
ren V19024   house
ren V19033    rent
ren V20022   disab
ren V20012  outkid
ren V20116     vet
ren V19111   fstmp
ren V19074   hourw
ren V19003   state
ren V19006    smsa
ren V19007   split
ren V19010    fchg
ren V19044   hours
ren V19098   fsize
ren V19002      id
*ren V19349     age
*ren V19351    agew
ren V19350     sex
ren V19352    kids
ren V19393   empst
ren V19396    self
ren V20082   newhd
ren V20114    race
ren V20175       y
ren V20178      ly
ren V19136     wly
ren V19151    tyhw
ren V19301   tyoth
ren V19317   troth
ren V19201    trhw
ren V20187    avhy
ren V19152 giveamt
ren V19153 givechsup
ren V19154 givealim
ren V19177 increlh
ren V19197 increlw
ren V19314 increlofum
ren V20216   marit
ren V20243  weight
ren V19107    food
ren V19109    fout
gen           ftax=V20162+V20174 if V20162!=. & V20174!=.
replace       ftax=V20162       if V20162!=. & V20174==.
replace       ftax=V20174       if V20162==. & V20174!=.
drop V20162 V20174
gen year=1990
tempfile fam90
save `fam90',replace


use "$rawdata/fam1992", clear
gen truncy=V21481==9999999
gen trunca=V20440==-9999
#delimit;
keep V20303 V20306 V20307 V20310 V20344 V20398 V20302 V20651 V20652 V20653 V20654 V20693 V20696 V21388 V21420 
     V21481 V21484 V20436 V20451 V20601 V20617 V20501 
     V21493 V21522 V21547 V21504 V20407 V20409 V20374
     V20438-V20441 V20444 V20446 V20448 V20449 V20603 V20501 V20617 V20411 V21422 V21312 V21322 V20333 V20324 V20429 trunc* 
     V20699 V20700 V20477 V20497 V20614 V20693
	 V20452 V20453 V20454 V20477 V20497 V20614 V20995 V21504 V21505 V20621 V21404 V21340 V21460 V21386  V21298 V21297
;
#delimit cr
ren	V21297	whousework_wk

ren	V21298	housework_wk

ren	V21386	wexp_18

ren	V21460	exp_18

ren	V21340	wfather_educ

ren	V21404	father_educ

ren	V20621	id67
ren V20699 unionj 
ren V20700 unioni 
rename	V21504	schooling
rename	V21505	w_schooling
rename	V20995	w_empl_status

gen asset=V20438+V20439+V20440+V20441+V20444+V20446+V20448+V20449+V20603
drop V20438-V20441 V20444 V20446 V20448 V20449 V20603
gen  ncars=.
gen   util=.
ren V20429   wages
ren V20324   house
ren V20333    rent
ren V21322   disab
ren V21312  outkid
ren V21422     vet
ren V20411   fstmp
ren V20374   hourw
ren V20303   state
ren V20306    smsa
ren V20307   split
ren V20310    fchg
ren V20344   hours
ren V20398   fsize
ren V20302      id
*ren V20651     age
*ren V20653    agew
ren V20652     sex
ren V20654    kids
ren V20693   empst
ren V20696    self
ren V21388   newhd
ren V21420    race
ren V21481       y
ren V21484      ly
ren V20436     wly
ren V20451    tyhw
ren V20601   tyoth
ren V20617   troth
ren V20501    trhw
ren V21493    avhy
ren V20452 giveamt
ren V20453 givechsup
ren V20454 givealim
ren V20477 increlh
ren V20497 increlw
ren V20614 increlofum
ren V21522   marit
ren V21547  weight
ren V20407    food
ren V20409    fout
gen           ftax=0
gen year=1991
tempfile fam91
save `fam91',replace

use "$rawdata/fam1993", clear
gen truncy=0
gen trunca=0
#delimit;
keep V21603 V21605 V21606 V21608 V21634 V22405 V21602 V22406 V22407 V22408 V22409 V22448 V22451 V23245 V23276 	 
     V23322 V23323 V23324 V21959 V22373 V22397 V22366 
     V23336 V23361 V23333 V21707 V21711 V21670
     V21809 V21813 V21810 V21814 V21811 V21812 V21829 V21845 V21861 V21893 V21877 V21909 V21925 V21957 V21941 V22371
     V22366 V22397 V21727 V23278 V23171 V23181 V21622 V21610 V21739 trunc*
	 V22454 V22455 V22156 V22333 V22392 V22448 
	 V22142 V22143 V22158 V22159 V22319 V22320 V22335 V22336 V21960 V21961 V21962 V22392 V22801 V23334 V22400 V23260  V23197 V23316 V23243 V23333 V23156 V23154
	 ;
#delimit cr
ren	V23154	whousework_wk

ren	V23156	housework_wk

ren	V23243	wexp_18

ren	V23316	exp_18

ren	V23197	wfather_educ

ren	V23260	father_educ

ren	V22400	id67
ren V22454 unionj 
ren V22455 unioni 
rename	V22801	w_empl_status
rename	V23333	schooling
rename	V23334	w_schooling

gen asset=V21809+V21813+V21810+V21814+V21811+V21812+V21829+V21845+V21861+V21893+V21877+V21909+V21925+V21957+V21941+V22371
drop V21809 V21813 V21810 V21814 V21811 V21812 V21829 V21845 V21861 V21893 V21877 V21909 V21925 V21957 V21941 V22371
gen  ncars=.
gen   util=.
ren V21739   wages
ren V21610   house
ren V21622    rent
ren V23181   disab
ren V23171  outkid
ren V23278     vet
ren V21727   fstmp
ren V21670   hourw
ren V21603   state
ren V21605    smsa
ren V21606   split
ren V21608    fchg
ren V21634   hours
ren V22405   fsize
ren V21602      id
*ren V22406     age
*ren V22408    agew
ren V22407     sex
ren V22409    kids
ren V22448   empst
ren V22451    self
ren V23245   newhd
ren V23276    race
ren V23322       y
ren V23323      ly
ren V23324     wly
ren V21959    tyhw
ren V22373   tyoth
ren V22397   troth
ren V22366    trhw
gen avhy=ly/hours
ren V22142 increlamth
ren V22143 increlperh
ren V22158 incnrelamth
ren V22159 incnrelperh
ren V22319 increlamtw
ren V22320 increlperw
ren V22335 incnrelamtw
ren V22336 incnrelperw
ren V21960 giveamt
ren V21961 givechsup
ren V21962 givealim 
ren V22392 increlofum
ren V23336   marit
ren V23361  weight
ren V21707    food
ren V21711    fout
gen          ftax=0
gen year=1992
tempfile fam92
save `fam92',replace

* Append all years together
use `fam67', clear
local i=68
forval i=68/92 {
	append using `fam`i''
}

rename empst  empl_status
order  id id67 year state  fsize  empl_status w_empl_status ly wly marit weduc educ father_educ wfather_educ exp_18 wexp_18 schooling w_schooling kids whousework_wk housework_wk
save "family.dta", replace

***********************************************************
***** 4. Merge to heads/spouse file and clean variables for analysis *****
***********************************************************

* Merge

u "family.dta", clear

drop V1008- V5852
drop  V7067- V10421
drop V11606- V19351
drop V20651 V20653 V22406 V22408

*order id year state marit educ weduc ly wly fsize race wages
rename educ heduc
sort id year
merge 1:1 id year using "couples.dta", gen(mfc)
keep if mfc==3

* Save
save "data.dta", replace

***********************************************************
***** 5. Create/ clean relevant variables *****
***********************************************************
u "data.dta", clear

* Unilateral divorce indicator
gen unilateral=0

replace unilateral=1 if state==1 & year>=1971
replace unilateral=1 if state==2 & year>=1973
replace unilateral=1 if state==4 & year>=1970
replace unilateral=1 if state==5 & year>=1972
replace unilateral=1 if state==6 & year>=1973
replace unilateral=1 if state==7 & year>=1968
replace unilateral=1 if state==9 & year>=1971
replace unilateral=1 if state==10 & year>=1973
replace unilateral=1 if state==11 & year>=1971
replace unilateral=1 if state==13 & year>=1973
replace unilateral=1 if state==14 & year>=1970
replace unilateral=1 if state==15 & year>=1969
replace unilateral=1 if state==16 & year>=1972
replace unilateral=1 if state==18 & year>=1973
replace unilateral=1 if state==20 & year>=1975
replace unilateral=1 if state==21 & year>=1972
replace unilateral=1 if state==22 & year>=1974
replace unilateral=1 if state==25 & year>=1973
replace unilateral=1 if state==26 & year>=1972
replace unilateral=1 if state==27 & year>=1967
replace unilateral=1 if state==28 & year>=1971
replace unilateral=1 if state==30 
replace unilateral=1 if state==33 & year>=1971
replace unilateral=1 if state==34 & year>=1992
replace unilateral=1 if state==35
replace unilateral=1 if state==36 & year>=1971
replace unilateral=1 if state==38 & year>=1975
replace unilateral=1 if state==40 & year>=1985
replace unilateral=1 if state==42 & year>=1970
replace unilateral=1 if state==43 & year>=1987
replace unilateral=1 if state==46 & year>=1973
replace unilateral=1 if state==47 & year>=1984
replace unilateral=1 if state==48 & year>=1978
replace unilateral=1 if state==49 & year>=1977
replace unilateral=1 if state==50
replace unilateral=1 if state==51 & year>=1972

replace state=. if state==0 | state==99
replace unilateral=. if state==.
label var unilateral "Unilateral"

* Year of UD by state

gen ud_year=. 
replace ud_year=1971 if state==1 
replace ud_year=1973 if state==2 
replace ud_year=1970 if state==4 
replace ud_year=1972 if state==5 
replace ud_year=1973 if state==6 
replace ud_year=1968 if state==7 
replace ud_year=1971 if state==9 
replace ud_year=1973 if state==10 
replace ud_year=1971 if state==11 
replace ud_year=1973 if state==13 
replace ud_year=1970 if state==14 
replace ud_year=1969 if state==15 
replace ud_year=1972 if state==16 
replace ud_year=1973 if state==18 
replace ud_year=1975 if state==20 
replace ud_year=1972 if state==21 
replace ud_year=1974 if state==22 
replace ud_year=1973 if state==25 
replace ud_year=1972 if state==26 
replace ud_year=1967 if state==27 
replace ud_year=1971 if state==28 
replace ud_year=1933 if state==30 //Gruber (2004)
replace ud_year=1971 if state==33 
replace ud_year=1992 if state==34 
replace ud_year=1953 if state==35 //Gruber (2004)
replace ud_year=1971 if state==36 
replace ud_year=1975 if state==38 
replace ud_year=1985 if state==40 
replace ud_year=1970 if state==42 
replace ud_year=1987 if state==43 
replace ud_year=1973 if state==46 
replace ud_year=1984 if state==47 
replace ud_year=1978 if state==48 
replace ud_year=1977 if state==49 
replace ud_year=1935 if state==50 //Gruber (2004)
replace ud_year=1972 if state==51 

save "households_psid.dta", replace




